if(typeof Ext.user.method.chartgroupstore == 'undefined'){ Ext.user.method.chartgroupstore = Ext.user.method.chartgroup(); }
if(typeof Ext.user.method.chartuserstore == 'undefined'){ Ext.user.method.chartuserstore = Ext.user.method.chartuser(); }
Ext.chart = {};
Ext.chart.left = [{border:false,xtype:'treepanel',
listeners:{
	click:function(n,e){
		if(n.attributes.id != 'menu'){
			var panel = Ext.getCmp('tongjitubiao');
			panel.removeAll();
			var aa = (Ext.get('tongjitubiao').query('*[class=x-panel-body]'))[0].id;
			if(n.attributes.id == 'all')
				panel.add(Ext.chart.rightGroupAll(aa));
			else
				panel.add(Ext.chart.rightGroup(aa));
		}
	}
},
root: {text:'统计类别',id: 'menu'},loader: {baseParams:{'do':'leftid'},url:Ext.user.baseUrl + '/Chart/data/',requestMethod: 'POST'}}];
Ext.chart.column = [
{title:'统计菜单',xtype:'panel',columnWidth:0.15,height:window.parent.Ext.getCmp('center_91').getHeight(),items:Ext.chart.left},
{id:'tongjitubiao',title:'统计图表',xtype:'panel',columnWidth:0.85,height:window.parent.Ext.getCmp('center_91').getHeight()}
];
Ext.chart.chartid = {xtype: 'combo',
			columnWidth: 0.15,	
			name:'type', 
			store:new Ext.data.JsonStore({
				data:[{'id':1,'name':'成员比例占有图'},{'id':2,'name':'各组员预约就诊情况图'},{'id':3,'name':'预约就诊月度走势图'}],
				fields:['id','name']
			}),
			displayField:'name',
			valueField:'id',
			hiddenName:'type',
			hiddenValue:'1',
			typeAhead: true,
			editable:false,
			forceSelection: true,
			mode:'local',
			triggerAction: 'all',
			emptyText:'请选择',	
			selectOnFocus:true,
			blankText:'不能为空',
			allowBlank:false,
		};
Ext.chart.chartdateidfunc = function(){
	return {xtype: 'combo',
			columnWidth: 0.10,	
			name:'dateselect', 
			store:new Ext.data.JsonStore({
				data:[{'id':1,'name':'选定日期范围'},{'id':2,'name':'选定月份范围'},{'id':3,'name':'指定月份'}],
				fields:['id','name']
			}),
			displayField:'name',
			valueField:'id',
			hiddenName:'dateselect',
			hiddenValue:'1',
			typeAhead: true,
			editable:false,
			forceSelection: true,
			mode:'local',
			triggerAction: 'all',
			emptyText:'请选择',	
			selectOnFocus:true,
			blankText:'不能为空',
			allowBlank:false,
			listeners:{
				select:function(c,r,i){
					switch(r.id){
						case 1:
							Ext.getCmp('date1').show();
							Ext.getCmp('date2').show();
							Ext.getCmp('date3').show();
							Ext.getCmp('date4').hide();
							Ext.getCmp('date5').hide();
							Ext.getCmp('date6').hide();
							Ext.getCmp('date7').hide();
							Ext.getCmp('date11').enable();
							Ext.getCmp('date33').enable();
							Ext.getCmp('date44').disable();
							Ext.getCmp('date55').disable();
							Ext.getCmp('date77').disable();
						break;
						case 2:
							Ext.getCmp('date1').hide();
							Ext.getCmp('date2').hide();
							Ext.getCmp('date3').hide();
							Ext.getCmp('date4').hide();
							Ext.getCmp('date5').show();
							Ext.getCmp('date6').show();
							Ext.getCmp('date7').show();
							Ext.getCmp('date11').disable();
							Ext.getCmp('date33').disable();
							Ext.getCmp('date44').disable();
							Ext.getCmp('date55').enable();
							Ext.getCmp('date77').enable();
						break;
						case 3:
							Ext.getCmp('date1').hide();
							Ext.getCmp('date2').hide();
							Ext.getCmp('date3').hide();
							Ext.getCmp('date4').show();
							Ext.getCmp('date5').hide();
							Ext.getCmp('date6').hide();
							Ext.getCmp('date7').hide();
							Ext.getCmp('date11').disable();
							Ext.getCmp('date33').disable();
							Ext.getCmp('date44').enable();
							Ext.getCmp('date55').disable();
							Ext.getCmp('date77').disable();
						break;
					}

				}		
			}
		};
}
Ext.chart.rightGroup = function (n) {
	var js,showitem,tbar;
	tbar = [];
	tbar[0] = [
		{xtype:'panel',columnWidth: 0.09,style:'margin-left:5px;margin-right:5px;line-height:20px;',html:'查询条件：'},
		{xtype: 'combo',
			columnWidth: 0.13,	
			name:'did', 
			store: Ext.user.method.chartgroupstore,
			displayField:'name',
			valueField:'did',
			hiddenName:'did',
			hiddenValue:'0',
			typeAhead: true,
			editable:false,
			forceSelection: true,
			mode:'local',
			triggerAction: 'all',
			emptyText:'请选择',	
			selectOnFocus:true
		},
		{xtype:'panel',columnWidth: 0.04,style:'margin-left:5px;line-height:20px;',html:'时间'},
		{id:'date1',xtype:'panel',columnWidth: 0.11,style:'margin-left:5px;line-height:20px;',items:[{id:'date11',name:'startdate',xtype:'datefield',format:'Y-m-d',allowBlank:false}]},
		{id:'date2',xtype:'panel',columnWidth: 0.02,style:'line-height:20px;',html:'至'},
		{id:'date3',xtype:'panel',columnWidth: 0.11,style:'margin-left:5px;line-height:20px;',items:[{id:'date33',name:'enddate',xtype:'datefield',format:'Y-m-d',allowBlank:false,}]},
		{id:'date4',xtype:'panel',columnWidth: 0.11,style:'margin-left:5px;line-height:20px;',items:[{id:'date44',name:'datemonth',xtype:'datefield',format:'Y-m',allowBlank:false}]},
		{id:'date5',xtype:'panel',columnWidth: 0.11,style:'margin-left:5px;line-height:20px;',items:[{id:'date55',name:'startmonth',xtype:'datefield',format:'Y-m',allowBlank:false}]},
		{id:'date6',xtype:'panel',columnWidth: 0.02,style:'line-height:20px;',html:'至'},
		{id:'date7',xtype:'panel',columnWidth: 0.11,style:'margin-left:5px;line-height:20px;',items:[{id:'date77',name:'endmonth',xtype:'datefield',format:'Y-m',allowBlank:false}]},
		{xtype:'panel',columnWidth: 0.06,style:'margin-left:5px;line-height:20px;',html:'显示图形'},
		Ext.chart.chartid,
		{xtype:'panel',columnWidth: 0.06,style:'margin-left:5px;line-height:20px;',html:'查询方式'},
		Ext.chart.chartdateidfunc(),
		{xtype:'panel',style:'margin-left:5px;',columnWidth: 0.05,items:[{xtype:'button',text:'查  找',handler:function(){
			Ext.getCmp('all').form.submit({
				method: 'POST',
				url:Ext.user.baseUrl + '/Chart/search/',
				success: function(f, a){
					var switchid = Ext.getCmp('all').form.getValues().type;
					switch(switchid){
						case '1':
							var win = new Ext.Window({title:'图表',id:'winchart1',autoHeight:true,width:820,modal:true,layout: 'column'});
							win.add(new Ext.Panel({'id':'chart_pie1',title:'预约统计图',columnWidth:0.5,border:false,autoHeight:true}));
							win.add(new Ext.Panel({'id':'chart_pie2',title:'就诊统计图',columnWidth:0.5,border:false,autoHeight:true}));
							win.show();
							var id1 = (Ext.get('chart_pie1').query('*[class=x-panel-body x-panel-body-noborder]'))[0].id; 
							var id2 = (Ext.get('chart_pie2').query('*[class=x-panel-body x-panel-body-noborder]'))[0].id; 
							var chart = new FusionCharts(Ext.SELF_DIR + "/FusionChartsFree/Charts/FCF_Pie2D.swf", "ChartId", "380", '320');
							chart.setDataXML(a.result.data.yuyue);	
							chart.render(id1);
							var chart1 = new FusionCharts(Ext.SELF_DIR + "/FusionChartsFree/Charts/FCF_Pie2D.swf", "ChartId", "380", '320');
							chart1.setDataXML(a.result.data.jiuzhen);	
							chart1.render(id2);
						break;
						case '2':
							var win = new Ext.Window({title:'图表',id:'winchart2',height:500,width:650,modal:true});
							win.show();
							var id = (Ext.get('winchart2').query('*[class=x-window-body]'))[0].id;
							var chart = new FusionCharts(Ext.SELF_DIR + "/FusionChartsFree/Charts/FCF_MSColumn2D.swf", "ChartId", "647", '462');
							chart.setDataXML(a.result.data);	
							chart.render(id);
						break;
						case '3':
							var win = new Ext.Window({title:'图表',id:'winchart3',height:458,width:939,modal:true});
							win.show();
							var id = (Ext.get('winchart3').query('*[class=x-window-body]'))[0].id;
							var chart = new FusionCharts(Ext.SELF_DIR + "/FusionChartsFree/Charts/FCF_MSLine.swf", "ChartId", "929", '438');
							chart.setDataXML(a.result.data);
							chart.render(id);							
						break;
					}

				},
				failure: function(f,a){
						alert('aa');
				}
			});

		}}]}

	];
	tbar[1] = [
		{xtype:'panel',columnWidth: 0.09,style:'margin-left:5px;margin-right:5px;line-height:20px;',html:'查询条件：'},
		{xtype: 'combo',
			columnWidth: 0.13,	
			name:'did', 
			store: Ext.user.method.chartgroupstore,
			displayField:'name',
			valueField:'did',
			hiddenName:'did',
			hiddenValue:'0',
			typeAhead: true,
			editable:false,
			forceSelection: true,
			mode:'local',
			triggerAction: 'all',
			emptyText:'请选择',	
			selectOnFocus:true,
			allowBlank:false
		},
		{xtype:'panel',columnWidth: 0.11,style:'margin-left:5px;line-height:20px;',items:[{name:'datemonth',xtype:'datefield',format:'Y-m',allowBlank:false}]},
		{xtype:'panel',style:'margin-left:5px;',columnWidth: 0.11,items:[{xtype:'button',text:'导  出小组汇总表',handler:function(){
				Ext.getCmp('group').form.submit({
					method: 'POST',
					params:{'do':'count'},
					url:Ext.user.baseUrl + '/Chart/execl/',
					success: function(f, a){
						location = a.result.data;
					},
					failure: function(f,a){
						alert('生成失败');
					}
				});
			}}]}
		];
	tbar[2] = [
		{xtype:'panel',columnWidth: 0.09,style:'margin-left:5px;margin-right:5px;line-height:20px;',html:'查询条件：'},
		{xtype: 'combo',
			columnWidth: 0.13,	
			name:'did', 
			store: Ext.user.method.chartgroupstore,
			displayField:'name',
			valueField:'did',
			hiddenName:'did',
			hiddenValue:'0',
			typeAhead: true,
			editable:false,
			forceSelection: true,
			mode:'local',
			triggerAction: 'all',
			emptyText:'请选择',	
			selectOnFocus:true,
			allowBlank:false
		},
		{xtype:'panel',columnWidth: 0.11,style:'margin-left:5px;line-height:20px;',items:[{name:'dateday',xtype:'datefield',format:'Y-m-d',allowBlank:false}]},
		{xtype:'panel',style:'margin-left:5px;',columnWidth: 0.14,items:[{xtype:'button',text:'导  出预约日报表(组)',handler:function(){
				Ext.getCmp('group1').form.submit({
					method: 'POST',
					params:{'do':'group'},
					url:Ext.user.baseUrl + '/Chart/execl/',
					success: function(f, a){
						location = a.result.data;
					},
					failure: function(f,a){
						alert('生成失败');
					}
				});
			}}]}	
	];
	tbar[3] = [
		{xtype:'panel',columnWidth: 0.09,style:'margin-left:5px;margin-right:5px;line-height:20px;',html:'查询条件：'},
		{xtype: 'combo',
			columnWidth: 0.13,	
			name:'uid', 
			store: Ext.user.method.chartuserstore,
			displayField:'name',
			valueField:'id',
			hiddenName:'uid',
			hiddenValue:'0',
			typeAhead: true,
			editable:false,
			forceSelection: true,
			mode:'local',
			triggerAction: 'all',
			emptyText:'请选择',	
			selectOnFocus:true,
			allowBlank:false
		},
		{xtype:'panel',columnWidth: 0.11,style:'margin-left:5px;line-height:20px;',items:[{name:'datemonth',xtype:'datefield',format:'Y-m',allowBlank:false}]},
		{xtype:'panel',style:'margin-left:5px;',columnWidth: 0.14,items:[{xtype:'button',text:'导  出预约情况表(个人)',handler:function(){
				Ext.getCmp('one').form.submit({
					method: 'POST',
					params:{'do':'one'},
					url:Ext.user.baseUrl + '/Chart/execl/',
					success: function(f, a){
						location = a.result.data;
					},
					failure: function(f,a){
						alert('生成失败');
					}
				});
			}}]},
	];
	showitem = [];
	showitem[0] = {border:false,frame:true,id:'all',xtype:'form',height:40,layout:'column',items:tbar[0]};
	showitem[1] = {border:false,frame:true,id:'group',xtype:'form',height:40,layout:'column',items:tbar[1]};
	showitem[2] = {border:false,frame:true,id:'group1',xtype:'form',height:40,layout:'column',items:tbar[2]};
	showitem[3] = {border:false,frame:true,id:'one',xtype:'form',height:40,layout:'column',items:tbar[3]};
	showitem[4] = {border:false,id:'rightGroup_body',xtype:'panel',autoHeight:true,html:''};
	js = new Ext.Panel({id:'rightGroup',border:false,items:showitem,renderTo:n});
	Ext.getCmp('date4').hide();
	Ext.getCmp('date5').hide();
	Ext.getCmp('date6').hide();
	Ext.getCmp('date7').hide();
	Ext.getCmp('date44').disable();
	Ext.getCmp('date55').disable();
	Ext.getCmp('date77').disable();
	return js;
}
Ext.chart.rightGroupAll = function (n){
	var js,searchitem,showitem;
	js = new Ext.Panel({id:'rightGroupAll',border:false,html:'2',renderTo:n});
	return js;
}
Ext.user.chart = Ext.extend(Ext.Panel,{
	renderTo:'chart_index',
	border:false,
	layout:'column',
	initComponent: function() {
		this.items = Ext.chart.column;
		Ext.user.chart.superclass.initComponent.call(this);
	}
});